package com.ssy.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * PageServlet
 *
 * @author ssy
 * @date 2020/11/12
 **/
@WebServlet(urlPatterns = {"/page.do"})
public class PageControllerServlet extends HttpServlet {

    private static final long serialVersionUID = 1851267996195453306L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        if ("toMain".equals(type)) {
            toMain(req, resp);
        } else if ("userList".equals(type)) {
            userList(req, resp);
        } else if ("studentList".equals(type)) {
            studentList(req, resp);
        } else if ("classList".equals(type)) {
            classList(req, resp);
        } else if ("curriculumList".equals(type)) {
            curriculumList(req, resp);
        } else if ("courseList".equals(type)) {
            courseList(req, resp);
        } else if ("scoreList".equals(type)) {
            scoreList(req, resp);
        } else if ("studentInfo".equals(type)) {
            studentInfo(req, resp);
        } else if ("curriculumInfo".equals(type)) {
            curriculumInfo(req, resp);
        } else if ("scoreInfo".equals(type)) {
            scoreInfo(req, resp);
        }
    }

    /**
     * 跳转成绩信息页面
     *
     * @param req
     * @param resp
     */
    private void scoreInfo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/student/scoreInfo.jsp").forward(req, resp);
    }

    /**
     * 跳转课程表信息页面
     *
     * @param req
     * @param resp
     */
    private void curriculumInfo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/student/curriculumInfo.jsp").forward(req, resp);
    }

    /**
     * 跳转学生信息页面
     *
     * @param req
     * @param resp
     */
    private void studentInfo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/student/studentInfo.jsp").forward(req, resp);
    }

    /**
     * 跳转到成绩列表
     *
     * @param req
     * @param resp
     */
    private void scoreList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/scoreList.jsp").forward(req, resp);
    }

    /**
     * 跳转到课程管理页面
     *
     * @param req
     * @param resp
     */
    private void courseList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/courseList.jsp").forward(req, resp);
    }


    /**
     * 跳转到课程表管理页面
     *
     * @param req
     * @param resp
     */
    private void curriculumList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/curriculumList.jsp").forward(req, resp);
    }

    /**
     * 跳转到  main.jsp
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    public void toMain(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/main.jsp").forward(req, resp);
    }

    /**
     * 跳转到用户列表
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    public void userList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/userList.jsp").forward(req, resp);
    }

    /**
     * 跳转到用户列表
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    public void studentList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/studentList.jsp").forward(req, resp);
    }

    /**
     * 跳转到班级列表
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    public void classList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("WEB-INF/jsp/classList.jsp").forward(req, resp);
    }

}
